package game;
import dgo.IO;
import dgo.MyLib;
import starruby.Texture;
import java.util.Hashtable;
import org.json.me.JSONObject;

public class GlobalModel{
  public boolean[] switches;
  public int[] variables;
  public int screenRed, screenGreen, screenBlue;
  public JSONObject charasetsSetting;
  public Texture gameScreen;
  public GlobalModel(Texture gameScreen){
    this.gameScreen = gameScreen;
    charasetsSetting = loadCharacterSetsSetting();
    switches = new boolean[100];
    variables = new int[50];
    screenRed = 0;
    screenGreen = 0;
    screenBlue = 0;
  }
  
  public void reset(){
    switches = new boolean[100];
    variables = new int[50];
  }
  
  private JSONObject loadCharacterSetsSetting(){
    return IO.getJSONObject(this.getClass(), "/data/common/charasets_setting.json");
  }
  
  public Hashtable loadStartInfo(){
    return IO.readHashFromJSON(this.getClass(), "/data/common/start.json");
  }
  
public Texture getTextTexture(String text){
    String[] texts = MyLib.split(text, "\n");
    int w = 0, h = 0, tw = 0, th = 0;

    for(int i=0; i< texts.length; i++){
      tw = gameScreen.g.getFont().stringWidth(texts[i]);
      th = gameScreen.g.getFont().getHeight();
      w = Math.max(tw, w);
    }
    w += 40;
    h = th * texts.length + 6;
   
    Texture tex = new Texture(w, h, false);
    for(int i=0; i< texts.length; i++){
      tex.renderText(texts[i], 0, i * th);
    }
    return tex;
}
}